package com.simpleplayer.views.customview;

import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import com.simpleplayer.R;

import java.util.Objects;

public class CustomDialog extends AlertDialog {

    private TextView mTipView;
    private String tip;

    public CustomDialog(@NonNull Context context) {
        super(context);
    }

    public CustomDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected CustomDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_dialog);

        mTipView = (TextView) findViewById(R.id.tip);
        TextView confirmView = (TextView) findViewById(R.id.confirm);
        if (tip != null) {
            mTipView.setText(tip);
        }
        Objects.requireNonNull(confirmView).setOnClickListener(v->{
            dismiss();
        });
    }

    public void setTip(String tip) {
        this.tip = tip;
        if (mTipView != null) {
            mTipView.setText(tip);
        }
    }
}
